define(function(require, exports){
	var $		= require('jquery');
	var pubjs	= require('pubjs');
	var view	= require('@base/view');
	var util	= require('util');

	var TERMINAL_TYPE = pubjs.config("CONST/TERMINAL_TYPE") || [];
	var TRADE_TYPE = pubjs.config("CONST/TRADE_TYPE") || [];
	var OS_TYPE = pubjs.config("CONST/OS_TYPE") || [];
	// 渠道资源报表

	var channel = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-overview',
				'grid': null
			});
			this.Super('init', arguments);
		},
		afterBuild:function(){
			this.append($([
				'<div class="M-formHead">',
				'<span class="M-formHeadTitle">'+LANG('')+'</span>',
				'<span class="fr" pub-name="date" pub-mod="@base/common/date.dateRangeNew"/>',
				'</div>',
				'<div class="cl" pub-name="grid" pub-mod="report/grid/resource/list.channelGrid"/>'
			].join('')));

			var c = this.getConfig();

			this.buildFromTemplate({
				'date': {
					'pos': 'bR',
					'userStorage': false
				},
				'grid': $.extend({
					'auto_load': true,
					'param': {
						'begindate': util.today(),
						'enddate': util.todayEnd()
					},
					'userStorageDate': false,
					'hasSearch': true,
					'gridName': 'channelSet',
					'hasFilterSidebar': true,
					'sidebar_config': {
						'items': [
							{'name': 'client', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('终端：'),
								'data': TERMINAL_TYPE,
								value:0
							}},
							{'name': 'terminal_os', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('系统：'),
								'data': OS_TYPE,
								value:0
							}},
							{'name': 'type', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('类型：'),
								'data': TRADE_TYPE,
								value:0
							}}
						]
					}
				}, c.grid)
			});
		},
		reload: function(param){
			this.$.grid.reload(param);
		}
		,onSidebarFilter: function(ev){
			var self = this
				,param = {};

			util.each(ev.param, function(item, idx){
				var type = idx;
				var id = item.id;

				switch (type) {
					case 'client':
						param.Clients = +id;
						break;
					case 'terminal_os':
						param.terminal_os = +id;
						break;
					case 'type':
						param.type = +id;
						break;
				}
			});
			self.$.grid.setParam(param).load();
		}
	});
	exports.channel = channel;
	// 广告位报表
	var adsense =view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-overview'
			});
			this.Super('init', arguments);
		},
		afterBuild:function(){
			this.append($([
				'<div class="M-formHead">',
				'<span class="M-formHeadTitle">'+LANG('')+'</span>',
				'<span class="fr" pub-name="date" pub-mod="@base/common/date.dateRangeNew"/>',
				'</div>',
				'<div class="cl" pub-name="grid" pub-mod="report/grid/resource/list.adsenseGrid"/>'
			].join('')));

			var c = this.getConfig();
			var self = this;
			this.buildFromTemplate({
				'date': {
					'pos': 'bR',
					'userStorage': false
				},
				'grid': {
					'auto_load': true,
					// 'param': {
					// 	'begindate': util.today(),
					// 	'enddate': util.todayEnd()
					// },
					'userStorageDate': false,
					'hasSearch': true,
					'gridName': 'overview_channel',
					'hasFilterSidebar': true,
					'sidebar_config': {
						'items': [
							{'name': 'client', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('终端：'),
								'data': TERMINAL_TYPE,
								'value':0
							}},
							{'name': 'terminal_os', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('系统：'),
								'data': OS_TYPE,
								'value':0
							}},
							{'name': 'type', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('类型：'),
								'data': TRADE_TYPE,
								'value':0
							}},
							{'name': 'channel_id', 'uri':'modules/sideBarBase.channel','config':{}}
						]
					}
				}
			});
		},
		reload: function(param){
			this.$.grid.reload(param);
		}
		,onSidebarFilter: function(ev){
			var self = this
				,param = {};
			util.each(ev.param, function(item, idx){
				var type = idx;
				var id = item.id;

				switch (type) {
					case 'client':
						param.Clients = +id;
						break;
					case 'terminal_os':
						param.terminal_os = +id;
						break;
					case 'type':
						param.type = +id;
						break;
					case 'channel_id':
						param.channel_id = +id;
						break;
				}
			});
			self.$.grid.setParam(param).load();
		}
	});
	exports.adsense = adsense;
	// 订单报表
	var order = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-overview'
			});
			this.Super('init', arguments);
		},
		afterBuild:function(){
			this.append($([
				'<div class="M-formHead">',
				'<span class="M-formHeadTitle">'+LANG('')+'</span>',
				'<span class="fr" pub-name="date" pub-mod="@base/common/date.dateRangeNew"/>',
				'</div>',
				'<div class="cl" pub-name="grid" pub-mod="report/grid/resource/list.orderGrid"/>'
			].join('')));

			var c = this.getConfig();

			this.buildFromTemplate({
				'date': {
					'pos': 'bR',
					'userStorage': false
				},
				'grid': {
					'auto_load': true,
					'param': {
						// 'begindate': util.today(),
						// 'enddate': util.todayEnd()
					},
					'userStorageDate': false,
					'hasSearch': true,
					'gridName': 'channelSet',
					'hasFilterSidebar': true,
					'sidebar_config': {
						'items': [
							{'name': 'client', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('终端：'),
								'data': TERMINAL_TYPE,
								'value':0
							}},
							{'name': 'terminal_os', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('系统：'),
								'data': OS_TYPE,
								'value':0
							}},
							{'name': 'type', 'uri':'modules/sideBarBase.radio', 'config': {
								'title': LANG('类型：'),
								'data': TRADE_TYPE,
								'value':0
							}},
							{'name': 'channel_id', 'uri':'modules/sideBarBase.channel','config':{}}

						]
					}
				}
			});
		},
		reload: function(param){
			this.$.grid.reload(param);
		}
		,onSidebarFilter: function(ev){
			var self = this
				,param = {};
			util.each(ev.param, function(item, idx){
				var type = idx;
				var id = item.id;

				switch (type) {
					case 'client':
						param.Clients = +id;
						break;
					case 'terminal_os':
						param.terminal_os = +id;
						break;
					case 'type':
						param.type = +id;
						break;
					case 'channel_id':
						param.channel_id = +id;
						break;
				}
			});
			self.$.grid.setParam(param).load();
		}
	});
	exports.order = order;
});